package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.StudentBean;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.apache.ibatis.session.SqlSession;

public class StudentServiceImpl extends BaseService implements IStudentService {
    @Override
    public PageInfo<StudentBean> cutByItem(Integer pageNO, String stuName, String className, String roomAddress) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        PageHelper.startPage(pageNO,2);
        PageInfo<StudentBean> pg = PageInfo.of(mapper.cutByItem(stuName,className,roomAddress));
        session.close();
        return pg;
    }

    @Override
    public void add(StudentBean student) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.add(student);
        session.commit();
        session.close();
    }

    @Override
    public void del(Integer stuId) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.del(stuId);
        session.commit();
        session.close();
    }

    @Override
    public void update(Integer stuId, Integer roomId) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.update(stuId,roomId);
        session.commit();
        session.close();
    }

    @Override
    public StudentBean findById(Integer stuId) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        StudentBean student = mapper.findById(stuId);
        session.close();
        return student;
    }
}
